<script language=VBScript runat=Server>

' Today - returns YYYYMMDD
Function Today()
    Dim y
    Dim m
    Dim d

    y = Year(Date)
    m = Month(Date)
    if m < 10 then
        m = "0" & m
    end if
    d = Day(Date)
    if d < 10 then
        d = "0" & d
    end if

    Today = "" & y & m & d
End Function

'WriteQueryLog
'
Sub WriteQueryLog(dtype, docid, pr)
    Dim cn
    Dim tabname
    Dim sql
    Dim printed
    Dim id, cno
    Dim RRdoc_type
    Dim LibraryLogonID, LibraryObject
    Dim ResultRecordset, Connect, QueryCommandText

    'FDS 890824 move below
    'QueryCommandText = "SELECT master_id, ecc_no FROM FNDOCUMENT WHERE F_DOCNUMBER = '" & trim(docid) & "'"

    'Copy from qresult.asp =====>
'Now we can do a search.
set ResultRecordset = Server.CreateObject("ADODB.Recordset")
ResultRecordset.MaxRecords = 200
ResultRecordset.PageSize = 50

'Panagon IDM Web application uses the Session variable LibraryLogonID to keep track of
'whether the user has logged on.
LibraryLogonID = Session("LibraryLogonID")
Set LibraryObject = Server.CreateObject("IDMObjects.Library")
LibraryObject.LogonId = LibraryLogonID

'Setup the connection string and other parameters.
Connect = "provider=FnDBProvider;data source=" + Session("LibraryName") + ";" + _
    "SystemType=" + CStr(LibraryObject.SystemType) + ";LogonID=" + LibraryLogonID + ";Prompt=4;"
ResultRecordset.ActiveConnection = Connect
ResultRecordset.Properties("SupportsObjSet") = True
ResultRecordset.Properties("SearchFolderName") = "/"
ResultRecordset.Properties("SearchSubfolder") = False
ResultRecordset.Properties("SearchDocumentState") = 0

'Execute the search.
On Error Resume Next

'FDS 890824 move below
'ResultRecordset.Open QueryCommandText, , adOpenKeyset

    '<===== Copy from qresult.asp 

    Select Case dtype
    case 1:
        QueryCommandText = "x"
        'ResultRecordset.Open QueryCommandText, , adOpenKeyset

        tabname = "C"
        id = "x"
        cno = "x"
    case 2:
        QueryCommandText = "x"
        'ResultRecordset.Open QueryCommandText, , adOpenKeyset

        tabname = "M"
        id = "x"
        cno = "x"
    case 3:
        QueryCommandText = "x"
        'ResultRecordset.Open QueryCommandText, , adOpenKeyset

        tabname = "S"
        id = "x"
        cno = "x"
    case 4:
        QueryCommandText = "SELECT master_id, ecc_no16 FROM FNDOCUMENT WHERE F_DOCNUMBER = '" & trim(docid) & "'" 'FDS 900205 ecc_no16
        ResultRecordset.Open QueryCommandText, , adOpenKeyset

        tabname = "CL"
        id = ResultRecordset.Fields(0) 'master_id
        cno = ResultRecordset.Fields(1) 'ecc_no
    case 5: '890731
        QueryCommandText = "SELECT master_id, card_no FROM FNDOCUMENT WHERE F_DOCNUMBER = '" & trim(docid) & "'"
        ResultRecordset.Open QueryCommandText, , adOpenKeyset

        tabname = "VD"
        id = ResultRecordset.Fields(0) 'master_id
        cno = ResultRecordset.Fields(1) 'card_no
'    case 6:
'	QueryCommandText = "SELECT master_id, card_no FROM FNDOCUMENT WHERE F_DOCNUMBER = '" & trim(docid) & "'"
'        ResultRecordset.Open QueryCommandText, , adOpenKeyset
'
'        tabname = "B"
'        id = ResultRecordset.Fields(0) 'master_id
'        cno = ResultRecordset.Fields(1) 'card_no
'    case 7:
'	QueryCommandText = "SELECT master_id, ecc_no16 FROM FNDOCUMENT WHERE F_DOCNUMBER = '" & trim(docid) & "'"
'        ResultRecordset.Open QueryCommandText, , adOpenKeyset
'
'        tabname = "B"
'        id = ResultRecordset.Fields(0) 'master_id
'        cno = ResultRecordset.Fields(1) 'card_no
    case Else
	QueryCommandText = "SELECT master_id, card_no, ecc_no16, doc_type FROM FNDOCUMENT WHERE F_DOCNUMBER = '" & trim(docid) & "'"
        ResultRecordset.Open QueryCommandText, , adOpenKeyset

        tabname = "B"
	RRdoc_type= ResultRecordset.Fields(3)
	if RRdoc_type="06" then
        id = ResultRecordset.Fields(0) 'master_id
        cno = ResultRecordset.Fields(1) 'card_no
	else
		if RRdoc_Type="07" then
			id = ResultRecordset.Fields(0) 'master_id
		        cno = ResultRecordset.Fields(2) 'card_no
		else

        tabname = "XX"
        id = "X"
        cno = "X"
		end if
	end if
    End Select

    tabname = tabname & "Querylog"

    if pr then
        printed = "1"
    else
        printed = "0"
    end if


    Set cn = Server.CreateObject("ADODB.Connection")
    cn.Open Application("OdbcConnStr") 'FDS 890824 "DSN=ctcb;UID=sa;PWD=FDSSQLSA;DATABASE=ctcb"
    
    Select Case RRdoc_type
    case 6:
	sql = "insert into " & tabname & _
      	" (userid, dept, qdate, holder_id, docclass, card_ecc_no, printed)" & _
      	" values('" & left(Session("Username"), 6) & "', '" & left(Session("DeptName"), 10) & "', '" & _
      	left(Today(), 8) & "', '" & left(id, 11) & "', '" & RRdoc_type & "', '" & left(cno, 16) & "', '" & _
      	printed & "')"
    case 7:
	sql = "insert into " & tabname & _
      	" (userid, dept, qdate, holder_id, docclass, card_ecc_no, printed)" & _
      	" values('" & left(Session("Username"), 6) & "', '" & left(Session("DeptName"), 10) & "', '" & _
      	left(Today(), 8) & "', '" & left(id, 11) & "', '" & RRdoc_type & "', '" & left(cno, 16) & "', '" & _
      	printed & "')"
    case else
    	sql = "insert into " & tabname & _
      	" (userid, dept, qdate, holder_id, card_no, printed)" & _
      	" values('" & left(Session("Username"), 6) & "', '" & left(Session("DeptName"), 10) & "', '" & _
      	left(Today(), 8) & "', '" & left(id, 11) & "', '" & left(cno, 16) & "', '" & _
      	printed & "')"
    end select
    
    cn.Execute sql
    
    cn.Close
    Set cn = Nothing
End Sub

'WriteCheckoutLog
'
Sub WriteCheckoutLog(dtype, docid, memo)
    Dim cn
    Dim tabname
    Dim sql
    Dim odate, id, cno
    Dim RRdoc_type, formid
    Dim LibraryLogonID, LibraryObject
    Dim ResultRecordset, Connect, QueryCommandText

    'FDS 890824 move below
    'QueryCommandText = "SELECT open_date, master_id, ecc_no FROM FNDOCUMENT WHERE F_DOCNUMBER = '" & trim(docid) & "'"

    'Copy from qresult.asp =====>
'Now we can do a search.
set ResultRecordset = Server.CreateObject("ADODB.Recordset")
ResultRecordset.MaxRecords = 200
ResultRecordset.PageSize = 50

'Panagon IDM Web application uses the Session variable LibraryLogonID to keep track of
'whether the user has logged on.
LibraryLogonID = Session("LibraryLogonID")
Set LibraryObject = Server.CreateObject("IDMObjects.Library")
LibraryObject.LogonId = LibraryLogonID

'Setup the connection string and other parameters.
Connect = "provider=FnDBProvider;data source=" + Session("LibraryName") + ";" + _
    "SystemType=" + CStr(LibraryObject.SystemType) + ";LogonID=" + LibraryLogonID + ";Prompt=4;"
ResultRecordset.ActiveConnection = Connect
ResultRecordset.Properties("SupportsObjSet") = True
ResultRecordset.Properties("SearchFolderName") = "/"
ResultRecordset.Properties("SearchSubfolder") = False
ResultRecordset.Properties("SearchDocumentState") = 0

'Execute the search.
On Error Resume Next

'FDS 890824 move below
'ResultRecordset.Open QueryCommandText, , adOpenKeyset

    '<===== Copy from qresult.asp 


    Set cn = Server.CreateObject("ADODB.Connection")
    cn.Open Application("OdbcConnStr") 'FDS 890731 "DSN=ctcb;UID=sa;PWD=FDSSQLSA;DATABASE=ctcb"
    
    Select Case dtype
    case 1:
        tabname = "C"
    case 2:
        tabname = "M"
    case 3:
        tabname = "S"
    case 4:
        QueryCommandText = "SELECT open_date, master_id, ecc_no16 FROM FNDOCUMENT WHERE F_DOCNUMBER = '" & trim(docid) & "'" 'FDS 900205 ecc_no16
        ResultRecordset.Open QueryCommandText, , adOpenKeyset

        tabname = "CL"
        odate = ResultRecordset.Fields(0) 'open_date    
        id = ResultRecordset.Fields(1) 'master_id
        cno = ResultRecordset.Fields(2) 'ecc_no
    case 5: '890731
        QueryCommandText = "SELECT open_date, master_id, card_no FROM FNDOCUMENT WHERE F_DOCNUMBER = '" & trim(docid) & "'"
        ResultRecordset.Open QueryCommandText, , adOpenKeyset

        tabname = "VD"
        odate = ResultRecordset.Fields(0) 'open_date    
        id = ResultRecordset.Fields(1) 'master_id
        cno = ResultRecordset.Fields(2) 'card_no
'    case 6:
'	QueryCommandText = "SELECT open_date, master_id, card_no FROM FNDOCUMENT WHERE F_DOCNUMBER = '" & trim(docid) & "'"
'       ResultRecordset.Open QueryCommandText, , adOpenKeyset
'
'        tabname = "B"
'        odate = ResultRecordset.Fields(0) 'open_date    
'        id = ResultRecordset.Fields(1) 'master_id
'        cno = ResultRecordset.Fields(2) 'card_no
'    case 7:
'	QueryCommandText = "SELECT open_date, master_id, ecc_no16 FROM FNDOCUMENT WHERE F_DOCNUMBER = '" & trim(docid) & "'"
'        ResultRecordset.Open QueryCommandText, , adOpenKeyset
'
'        tabname = "B"
'        odate = ResultRecordset.Fields(0) 'open_date    
'        id = ResultRecordset.Fields(1) 'master_id
'        cno = ResultRecordset.Fields(2) 'card_no
    case Else
	QueryCommandText = "SELECT open_date, master_id, card_no, ecc_no16, doc_type, form_id FROM FNDOCUMENT WHERE F_DOCNUMBER = '" & trim(docid) & "'"
        ResultRecordset.Open QueryCommandText, , adOpenKeyset

        tabname = "B"
	RRdoc_type=ResultRecordset.Fields(4)
	if RRdoc_type="06" then
		odate = ResultRecordset.Fields(0) 'open_date    
	        id = ResultRecordset.Fields(1) 'master_id
        	cno = ResultRecordset.Fields(2) 'card_no
		formid = ResultRecordset.Fields(5)
	else
		if RRdoc_type="07" then
			odate = ResultRecordset.Fields(0) 'open_date    
		        id = ResultRecordset.Fields(1) 'master_id
        		cno = ResultRecordset.Fields(3) 'card_no
			formid = ResultRecordset.Fields(5)
		else
        tabname = "XX"
		end if
	end if
    End Select

    tabname = tabname & "Checkout"

    Select Case RRdoc_type
    case 6:
	sql = "insert into " & tabname & _
      	" (userid, dept, adate, open_date, ssn, docclass, card_ecc_no, holder_id, receive_no, formid, printed, memo)" & _
      	" values('" & left(Session("Username"), 6) & "', '" & left(Session("DeptName"), 10) & "', '" & _
      	left(Today(), 8) & "', '" & left(odate, 8) & "', ' ', '" & RRdoc_type & "', '" & left(cno, 16) & "', '" & left(id, 11) & "', ' ', '" & formid & "', '0', '" & _
      	memo & "')"
    case 7:
	sql = "insert into " & tabname & _
      	" (userid, dept, adate, open_date, ssn, docclass, card_ecc_no, holder_id, receive_no, formid, printed, memo)" & _
      	" values('" & left(Session("Username"), 6) & "', '" & left(Session("DeptName"), 10) & "', '" & _
      	left(Today(), 8) & "', '" & left(odate, 8) & "', ' ', '" & RRdoc_type & "', '" & left(cno, 16) & "', '" & left(id, 11) & "', ' ', '" & formid & "', '0', '" & _
      	memo & "')"
    case else
    	sql = "insert into " & tabname & _
      	" (userid, dept, adate, open_date, ssn, card_no, holder_id, receive_no, printed, memo)" & _
      	" values('" & left(Session("Username"), 6) & "', '" & left(Session("DeptName"), 10) & "', '" & _
      	left(Today(), 8) & "', '" & left(odate, 8) & "', ' ', '" & left(cno, 16) & "', '" & left(id, 11) & "', ' ', '0', '" & _
      	memo & "')"
    end select
    
    cn.Execute sql
    
    cn.Close
    Set cn = Nothing
End Sub

'SearchEccNoFi
'
Function SearchEccNoFi(eccno)
    Dim cn
    Dim rs
    Dim sql
    
    Set cn = Server.CreateObject("ADODB.Connection")
    cn.Open Application("OdbcConnStr") 'FDS 890731 "DSN=ctcb;UID=sa;PWD=FDSSQLSA;DATABASE=ctcb"
            
    sql = "select * from idxCLoan"
    sql = sql & " where EccNo = '" & Trim(eccno) & "'"

    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open sql, cn

    if rs.Eof then
        SearchEccNoFi = "Not Found"
        rs.Close
        Set rs = Nothing
        cn.Close
        Set cn = Nothing
        Exit Function
    end if

    rs.MoveFirst

    SearchEccNoFi = rs.Fields("EccNoFi")

    rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
End Function

</script>
